﻿using Global.Globalcs;
using PHZPNW.API;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Services;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

/// <summary>
/// JsWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class JsWebService : WebService
{
    MSql msql = new MSql();
    qxgl qx = new qxgl();
    YGDA YG = new YGDA();
    TXL tl = new TXL();
    GG gg = new GG();
    public JsWebService()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }
    /***********************************角色权限分配接口************************************************/
    //载入用户页面部门权限表//设置最高支持6级
    [WebMethod]
    public string bmqx(string id, string uid)
    {
        string jdate = "[";
        string bmid = "";
        string bmname = "";
        string ckd = "";
        string sql = "select * from s_bm where bmjb = 0";
        DataSet yj = msql.Selbeck(sql);
        for (int a = 0; a < yj.Tables[0].Rows.Count; a++)
        {
            bmid = yj.Tables[0].Rows[a]["id"].ToString();
            bmname = yj.Tables[0].Rows[a]["bmname"].ToString();
            sql = "select * from L_part where pid = '" + id + "' and  partid = '" + yj.Tables[0].Rows[a]["id"].ToString() + "' and roleid = '" + uid + "'";
            DataSet ck = msql.Getdataset(sql);
            if (ck.Tables[0].Rows.Count > 0)
            {
                ckd = "true";
            }
            else
            {
                ckd = "false";
            }
            jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
            //生成二级菜单
            sql = "select * from s_bm  where sjbm = '" + yj.Tables[0].Rows[a]["id"].ToString() + "' order by yxj";
            DataSet ej = msql.Getdataset(sql);
            for (int b = 0; b < ej.Tables[0].Rows.Count; b++)
            {
                bmid = ej.Tables[0].Rows[b]["id"].ToString();
                bmname = ej.Tables[0].Rows[b]["bmname"].ToString();
                sql = "select * from L_part where pid = '" + id + "' and  partid = '" + ej.Tables[0].Rows[b]["id"].ToString() + "' and roleid = '" + uid + "'";
                ck = msql.Getdataset(sql);
                if (ck.Tables[0].Rows.Count > 0)
                {
                    ckd = "true";
                }
                else
                {
                    ckd = "false";
                }
                jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
                //生成三级级菜单
                sql = "select * from s_bm  where sjbm = '" + ej.Tables[0].Rows[b]["id"].ToString() + "' order by yxj";
                DataSet sj = msql.Getdataset(sql);
                for (int c = 0; c < sj.Tables[0].Rows.Count; c++)
                {
                    bmid = sj.Tables[0].Rows[c]["id"].ToString();
                    bmname = sj.Tables[0].Rows[c]["bmname"].ToString();
                    sql = "select * from L_part where pid = '" + id + "' and  partid = '" + sj.Tables[0].Rows[c]["id"].ToString() + "' and roleid = '" + uid + "'";
                    ck = msql.Getdataset(sql);
                    if (ck.Tables[0].Rows.Count > 0)
                    {
                        ckd = "true";
                    }
                    else
                    {
                        ckd = "false";
                    }
                    jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
                    //生成四级级菜单
                    sql = "select * from s_bm  where sjbm = '" + sj.Tables[0].Rows[c]["id"].ToString() + "' order by yxj";
                    DataSet fj = msql.Getdataset(sql);
                    for (int d = 0; d < fj.Tables[0].Rows.Count; d++)
                    {
                        bmid = fj.Tables[0].Rows[d]["id"].ToString();
                        bmname = fj.Tables[0].Rows[d]["bmname"].ToString();
                        sql = "select * from L_part where pid = '" + id + "' and  partid = '" + sj.Tables[0].Rows[d]["id"].ToString() + "' and roleid = '" + uid + "'";
                        ck = msql.Getdataset(sql);
                        if (ck.Tables[0].Rows.Count > 0)
                        {
                            ckd = "true";
                        }
                        else
                        {
                            ckd = "false";
                        }
                        jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
                        //生成五级级菜单
                        sql = "select * from s_bm  where sjbm = '" + fj.Tables[0].Rows[d]["id"].ToString() + "' order by yxj";
                        DataSet wj = msql.Getdataset(sql);
                        for (int e = 0; e < wj.Tables[0].Rows.Count; e++)
                        {
                            bmid = wj.Tables[0].Rows[e]["id"].ToString();
                            bmname = wj.Tables[0].Rows[e]["bmname"].ToString();
                            sql = "select * from L_part where pid = '" + id + "' and  partid = '" + wj.Tables[0].Rows[e]["id"].ToString() + "' and roleid = '" + uid + "'";
                            ck = msql.Getdataset(sql);
                            if (ck.Tables[0].Rows.Count > 0)
                            {
                                ckd = "true";
                            }
                            else
                            {
                                ckd = "false";
                            }
                            jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
                            //生成六级级菜单
                            sql = "select * from s_bm  where sjbm = '" + wj.Tables[0].Rows[e]["id"].ToString() + "' order by yxj";
                            DataSet lj = msql.Getdataset(sql);
                            for (int f = 0; f < lj.Tables[0].Rows.Count; f++)
                            {
                                bmid = lj.Tables[0].Rows[f]["id"].ToString();
                                bmname = lj.Tables[0].Rows[f]["bmname"].ToString();
                                sql = "select * from L_part where pid = '" + id + "' and  partid = '" + lj.Tables[0].Rows[f]["id"].ToString() + "' and roleid = '" + uid + "'";
                                ck = msql.Getdataset(sql);
                                if (ck.Tables[0].Rows.Count > 0)
                                {
                                    ckd = "true";
                                }
                                else
                                {
                                    ckd = "false";
                                }
                                jdate = jdate + "{\"id\": \"" + bmid + "\",\"text\": \"" + bmname + "\",\"checked\": " + ckd + " ,\"children\": [";
                                if (f == lj.Tables[0].Rows.Count - 1)
                                {
                                    jdate = jdate + "]}";
                                }
                                else
                                {
                                    jdate = jdate + "]},";
                                }
                            }
                            if (e == wj.Tables[0].Rows.Count - 1)
                            {
                                jdate = jdate + "]}";
                            }
                            else
                            {
                                jdate = jdate + "]},";
                            }
                        }
                        if (d == fj.Tables[0].Rows.Count - 1)
                        {
                            jdate = jdate + "]}";
                        }
                        else
                        {
                            jdate = jdate + "]},";
                        }
                    }
                    if (c == sj.Tables[0].Rows.Count - 1)
                    {
                        jdate = jdate + "]}";
                    }
                    else
                    {
                        jdate = jdate + "]},";
                    }
                }
                if (b == ej.Tables[0].Rows.Count - 1)
                {
                    jdate = jdate + "]}";
                }
                else
                {
                    jdate = jdate + "]},";
                }
            }
            if (a == yj.Tables[0].Rows.Count - 1)
            {
                jdate = jdate + "]}";
            }
            else
            {
                jdate = jdate + "]},";
            }
        }
        jdate = jdate + "]";
        return jdate;
    }
    //修改页面信息临时表
    [WebMethod]
    public string ymcg(string id, string qxdj, string uid, bool cz)
    {
        string sql = "";
        DataSet ds;
        sql = "select * from l_role where roleid = '" + uid + "'";
        DataSet rinfo = msql.Selbeck(sql);
        string uname = rinfo.Tables[0].Rows[0]["rolename"].ToString();
        sql = "select Min(qxid) from l_role where roleid = '" + uid + "' and pid = '" + id + "'";
        ds = msql.Selbeck(sql);
        qxdj = qxdj.Substring(qxdj.Length - 1, 1);
        if (ds.Tables[0].Rows[0][0].ToString() == "")
        {
            string cid = msql.getmaxid("id", "l_role", "where roleid = '" + uid + "'");
            sql = "insert into L_role(id,roleid,rolename,pid,qxid)Values('" + cid + "','" + uid + "','" + uname + "','" + id + "','" + qxdj + "')";
            msql.Datachange(sql);
        }
        else
        {
            if (int.Parse(ds.Tables[0].Rows[0][0].ToString()) > int.Parse(qxdj))
            {
                if (cz)
                {
                    sql = "update L_role set qxid = '" + qxdj + "' where roleid = '" + uid + "' and pid = '" + id + "'";
                    msql.Datachange(sql);
                }
            }
            if (!cz)
            {
                sql = "delete L_role  where roleid = '" + uid + "' and pid = '" + id + "' and qxid = '" + qxdj + "'";
                msql.Datachange(sql);
            }
        }
        return "0";
    }
    //修改所有子节点默认为编辑或者删除所有子节点管理权限
    [WebMethod]
    public string ympcg(string id, string uid, bool cz)
    {
        string sql = "";
        sql = "select * from l_role where roleid = '" + uid + "'";
        DataSet rinfo = msql.Selbeck(sql);
        string uname = rinfo.Tables[0].Rows[0]["rolename"].ToString();
        if (cz)
        {
            string cid = msql.getmaxid("id", "l_role", "where roleid = '" + uid + "'");
            sql = "insert into L_role(id,roleid,rolename,pid,qxid)Values('" + uid + "','" + uid + "','" + uname + "','" + id + "',1)";
            msql.Datachange(sql);

            sql = "select * from s_menu where fmenu = '" + id + "'";
            DataSet ds = msql.Selbeck(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    cid = msql.getmaxid("id", "l_role", "where roleid = '" + uid + "'");
                    string pid = ds.Tables[0].Rows[i]["pageid"].ToString();
                    sql = "insert into L_role(id,roleid,rolename,pid,qxid)Values('" + cid + "','" + uid + "','" + uname + "','" + pid + "',1)";
                    msql.Datachange(sql);

                    string rjym = ds.Tables[0].Rows[i]["pageid"].ToString();
                    sql = "select * from s_menu where fmenu = '" + rjym + "'";
                    DataSet dt = msql.Selbeck(sql);
                    if (dt.Tables[0].Rows.Count > 0)
                    {
                        for (int m = 0; m < dt.Tables[0].Rows.Count; m++)
                        {
                            cid = msql.getmaxid("id", "l_role", "where roleid = '" + uid + "'");
                            pid = dt.Tables[0].Rows[m]["pageid"].ToString();
                            sql = "insert into L_role(id,roleid,rolename,pid,qxid)Values('" + cid + "','" + uid + "','" + uname + "','" + pid + "',1)";
                            msql.Datachange(sql);
                        }
                    }
                }
            }
            else
            {
                cid = msql.getmaxid("id", "l_role", "where roleid = '" + uid + "'");
                sql = "insert into L_role(id,roleid,rolename,pid,qxid)Values('" + cid + "','" + uid + "','" + uname + "','" + id + "',1)";
                msql.Datachange(sql);
            }
        }
        else
        {
            sql = "delete  from l_role where uid = '" + uid + "' and pid = '" + id + "'";
            msql.Datachange(sql);
            sql = "select * from s_menu where fmenu = '" + id + "'";
            DataSet ds = msql.Selbeck(sql);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string rjym = ds.Tables[0].Rows[i]["pageid"].ToString();
                sql = "delete  from l_role where roleid = '" + uid + "' and pid = '" + rjym + "'";
                msql.Datachange(sql);
                sql = "select * from s_menu where fmenu = '" + rjym + "'";
                DataSet dt = msql.Selbeck(sql);
                for (int m = 0; m < dt.Tables[0].Rows.Count; m++)
                {
                    string sjym = dt.Tables[0].Rows[i]["pageid"].ToString();
                    sql = "delete  from l_role where roleid = '" + uid + "' and pid = '" + sjym + "'";
                    msql.Datachange(sql);
                }
            }
        }
        return "0";
    }
    //修改部门信息临时表
    [WebMethod]
    public string bmcg(string id, string pid, string uid, bool cz)
    {
        string sql = "";
        DataSet ds;

        sql = "select * from l_part where roleid = '" + uid + "' and pid = '" + pid + "' and partid = '" + id + "'";
        ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (!cz)
            {
                sql = "delete l_part  where roleid = '" + uid + "' and pid = '" + pid + "' and partid = '" + id + "'";
                msql.Datachange(sql);
            }
        }
        else
        {
            if (cz)
            {
                string cid = msql.getmaxid("id", "l_part", "where roleid = '" + uid + "'");
                sql = "insert into l_part(id,roleid,partid,pid)Values('" + cid + "','" + uid + "','" + id + "','" + pid + "')";
                msql.Datachange(sql);
            }

        }
        return "0";
    }
    /**************************************页面编辑接口*********************************************/
    //更新菜单名称
    [WebMethod]
    public string udpage(string id, string pagename)
    {
        string errorlog = "";
        string sql = "select * from l_menu where id != '" + id + "' and pagename = '" + pagename + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            errorlog = "当前菜单名已存在，禁止修改";
        }
        else
        {
            sql = "update l_menu set pagename = '" + pagename + "' where  id = '" + id + "'";
            msql.Datachange(sql);
        }
        return errorlog;
    }
    //获取当前菜单信息
    [WebMethod]
    public string[] ccinfo(string id)
    {
        string[] info = new string[7];
        string sql = "select * from l_menu where id = '" + id + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            info[0] = ds.Tables[0].Rows[0]["id"].ToString();
            info[1] = ds.Tables[0].Rows[0]["pagename"].ToString();
            info[2] = ds.Tables[0].Rows[0]["fmenu"].ToString();
            info[3] = ds.Tables[0].Rows[0]["yxj"].ToString();
            info[4] = ds.Tables[0].Rows[0]["icon"].ToString();
            info[5] = ds.Tables[0].Rows[0]["url"].ToString();
            info[6] = ds.Tables[0].Rows[0]["lev"].ToString();
        }
        else
        {
            info[0] = "";
            info[1] = "";
            info[2] = "";
            info[3] = "";
            info[4] = "";
            info[5] = "";
            info[6] = "";
        }
        return info;
    }
    //菜单信息保存
    [WebMethod]
    public string pgsave(string pageid, string pagename, string fmenu, string yxj, string url)
    {
        string errorlog = "";//异常反馈
                             //先判断父级菜单是不是正常
        string sql = "select * from L_menu where id = '" + fmenu + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows[0]["lev"].ToString() == "2")
            {
                errorlog = errorlog + "三级菜单不允许作为父级菜单";
            }
        }
        else
        {
            errorlog = errorlog + "错误的父级菜单";
        }
        string lev = (int.Parse(ds.Tables[0].Rows[0]["lev"].ToString()) + 1).ToString();
        sql = "select * from L_menu where pageid != '" + pageid + "' and pagename = '" + pagename + "'";
        ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            errorlog = errorlog + "菜单名禁止重复";
        }
        if (pageid == "" || pagename == "" || fmenu == "" || yxj == "")
        {
            errorlog = errorlog + "菜单名/父级菜单/优先级必须输入信息";
        }
        if (findnum(yxj) == "" || findnum(fmenu) == "")
        {
            errorlog = errorlog + "父级菜单/优先级只能输入数字";
        }
        string filename = "../App_Data/1.txt";
        filename = Context.Server.MapPath(filename);
        //确认小图标
        StreamReader sr = new StreamReader(filename, Encoding.Default);
        //StreamReader sr = new StreamReader(filename, Encoding.UTF8);
        string icon;
        string tb = "";
        icon = sr.ReadLine();
        sr.Close();
        if (errorlog == "")
        {
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Write);//打开写入文件
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.Write("1");
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
            sql = "select * from l_menu where id = '" + pageid + "'";
            ds = msql.Selbeck(sql);
            msql.yxjcl("yxj", "l_menu", "where fmenu='" + fmenu + "' and id !=  '" + pageid + "'");
            if (ds.Tables[0].Rows.Count > 0)//修改
            {
                if (icon != "1")
                {
                    tb = " , icon = '" + icon + "'";
                }
                sql = "update l_menu set pagename = '" + pagename + "',fmenu='" + fmenu + "',yxj='" + yxj + "',url = '" + url + "',lev = '" + lev + "' " + tb + " where id = '" + pageid + "'";
            }
            else//新增
            {
                if (icon != "1")
                {
                    sql = "insert into l_menu(id,pageid,pagename,fmenu,yxj,icon,url,lev)Values('" + pageid + "','" + pageid + "','" + pagename + "','" + fmenu + "','" + yxj + "','" + icon + "'," +
                        "'" + url + "','" + lev + "')";
                }
                else
                {
                    sql = "insert into l_menu(id,pageid,pagename,fmenu,yxj,url,lev)Values('" + pageid + "','" + pageid + "','" + pagename + "','" + fmenu + "','" + yxj + "','" + url + "','" + lev + "')";
                }
            }
            msql.Datachange(sql);
        }
        return errorlog;
    }
    //添加子集菜单
    [WebMethod]
    public string[] hqid(string pageid)
    {
        string[] fhz = new string[5];
        string errorlog = "";//异常反馈
        string sql = "select * from L_menu where id = '" + pageid + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows[0]["lev"].ToString() == "2")
        {
            errorlog = errorlog + "三级菜单不允许作为父级菜单";
        }
        string lev = (int.Parse(ds.Tables[0].Rows[0]["lev"].ToString()) + 1).ToString();
        string id = "";
        string yxj = "";
        if (errorlog == "")
        {
            id = msql.getmaxid("id", "L_menu", "");
            yxj = msql.getid("yxj", "L_menu", " where fmenu = '" + pageid + "'");
        }
        fhz[0] = errorlog;
        fhz[1] = id;
        fhz[2] = yxj;
        fhz[3] = lev;
        fhz[4] = pageid;
        return fhz;
    }
    //删除菜单和子节点
    [WebMethod]
    public string jdsc(string id)
    {
        string sql = "delete L_menu where id = '" + id + "' or fmenu = '" + id + "'";
        msql.Datachange(sql);
        return "0";
    }
    /**************************************部门编辑接口*********************************************/
    [WebMethod]
    public string bmgx(string id, string bmname)
    {
        string errorlog = "";
        string sql = "select * from l_bm where id != '" + id + "' and bmname = '" + bmname + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            errorlog = "当前部门名已存在，禁止修改";
        }
        else
        {
            sql = "update l_bm set bmname = '" + bmname + "' where  id = '" + id + "'";
            msql.Datachange(sql);
        }
        return errorlog;
    }
    [WebMethod]
    public string[] bminfo(string id)
    {
        string[] info = new string[7];
        string sql = "select * from l_bm where id = '" + id + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            info[0] = ds.Tables[0].Rows[0]["id"].ToString();
            info[1] = ds.Tables[0].Rows[0]["bmname"].ToString();
            info[2] = ds.Tables[0].Rows[0]["sjbm"].ToString();
            info[3] = ds.Tables[0].Rows[0]["yxj"].ToString();
            info[4] = ds.Tables[0].Rows[0]["bmjb"].ToString();
        }
        else
        {
            info[0] = "";
            info[1] = "";
            info[2] = "";
            info[3] = "";
            info[4] = "";
            info[5] = "";
            info[6] = "";
        }
        return info;
    }
    //更新部门名称
    [WebMethod]
    public string bmmcgx(string id, string bmname)
    {
        string errorlog = "";
        string sql = "select * from l_bm where id != '" + id + "' and bmname = '" + bmname + "'";
        DataSet ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            errorlog = "当前部门名已存在，禁止修改";
        }
        else
        {
            sql = "update l_bm set bmname = '" + bmname + "' where  id = '" + id + "'";
            msql.Datachange(sql);
        }
        return errorlog;
    }
    //部门信息保存
    [WebMethod]
    public string bmsave(string bmid, string bmname, string sjbm, string yxj)
    {
        string errorlog = "";//异常反馈
        string sql = "select * from l_bm where id = '" + sjbm + "'";
        DataSet ds = msql.Selbeck(sql);
        string lev = "-1";
        if (ds.Tables[0].Rows.Count > 0)
        {
            lev = (int.Parse(ds.Tables[0].Rows[0]["bmjb"].ToString()) + 1).ToString();
        }
        else
        {
            errorlog = errorlog + "该上级部门不存在";
        }
        sql = "select * from l_bm where bmid != '" + bmid + "' and bmname = '" + bmname + "'";
        ds = msql.Selbeck(sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            errorlog = errorlog + "部门名禁止重复";
        }
        if (bmid == "" || bmname == "" || sjbm == "" || yxj == "")
        {
            errorlog = errorlog + "部门名/上级部门/优先级必须输入信息";
        }
        if (findnum(yxj) == "" || findnum(sjbm) == "")
        {
            errorlog = errorlog + "上级部门/优先级只能输入数字";
        }
        if (errorlog == "")
        {
            sql = "select * from l_bm where id = '" + bmid + "'";
            ds = msql.Selbeck(sql);
            msql.yxjcl("yxj", "l_bm", "where sjbm='" + sjbm + "' and id !=  '" + bmid + "'");
            if (ds.Tables[0].Rows.Count > 0)//修改
            {
                sql = "update l_bm set bmname = '" + bmname + "',sjbm='" + sjbm + "',yxj='" + yxj + "',bmjb = '" + lev + "'  where id = '" + bmid + "'";
            }
            else//新增
            {
                sql = "insert into l_bm(id,bmid,bmname,sjbm,yxj,bmjb)Values('" + bmid + "','" + bmid + "','" + bmname + "','" + sjbm + "','" + yxj + "','" + lev + "')";
            }
            msql.Datachange(sql);
        }
        return errorlog;
    }
    //添加子部门
    [WebMethod]
    public string[] bmid(string pageid)
    {
        string[] fhz = new string[5];
        string errorlog = "";//异常反馈
        string sql = "select * from l_bm where id = '" + pageid + "'";
        DataSet ds = msql.Selbeck(sql);
        string lev = (int.Parse(ds.Tables[0].Rows[0]["bmjb"].ToString()) + 1).ToString();
        string id = "";
        string yxj = "";
        if (errorlog == "")
        {
            id = msql.getmaxid("id", "l_bm", "");
            yxj = msql.getid("yxj", "l_bm", " where sjbm = '" + pageid + "'");
        }
        fhz[0] = errorlog;
        fhz[1] = id;
        fhz[2] = yxj;
        fhz[3] = lev;
        fhz[4] = pageid;
        return fhz;
    }
    //删除部门和子部门
    [WebMethod]
    public string bmsc(string id)
    {
        string sql = "delete l_bm where id = '" + id + "' or sjbm = '" + id + "'";
        msql.Datachange(sql);
        return "0";
    }
    /**********************************************动态加载角色信息**************************************************/
    //动态加载角色部门或者页面-角色信息
    [WebMethod]
    public string Loadrole(string id, string bp)
    {
        string jdate = "[";
        string roleid = "";
        string rolename = "";
        string ckbh = "";
        if (bp == "p")
        {
            string sql = "select roleid,rolename,jszt from s_role where jszt = 1 group by roleid,rolename,jszt order by roleid";
            DataSet ds = msql.Selbeck(sql);

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                roleid = ds.Tables[0].Rows[i]["roleid"].ToString();
                rolename = ds.Tables[0].Rows[i]["rolename"].ToString();
                //确认该页面该角色是否有操作权限
                sql = "select * from s_role where roleid = '" + roleid + "' and pid = '" + id + "'";
                DataSet dt = msql.Selbeck(sql);
                sql = "select * from s_role where roleid = '" + roleid + "' and pid = '" + id + "'";
                DataSet dc = msql.Selbeck(sql);

                if (dt.Tables[0].Rows.Count > 0 || dc.Tables[0].Rows.Count > 0)
                {
                    if (dc.Tables[0].Rows.Count > 0)
                    {
                        ckbh = dc.Tables[0].Rows[0]["qxid"].ToString();
                    }
                    else
                    {
                        ckbh = dt.Tables[0].Rows[0]["qxid"].ToString();
                    }

                    jdate = jdate + "{\"id\": \"" + roleid + "\",\"text\": \"" + rolename + "\",\"children\": [";
                    if (ckbh == "0")
                    {
                        jdate = jdate + "{ \"id\":\"" + roleid + "-1\",  \"text\":\"管理\",\"checked\":\"true\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-2\",  \"text\":\"编辑\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-3\",  \"text\":\"查看\"}";
                    }
                    else if (ckbh == "1")
                    {
                        jdate = jdate + "{ \"id\":\"" + roleid + "-1\",  \"text\":\"管理\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-2\",  \"text\":\"编辑\",\"checked\":\"true\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-3\",  \"text\":\"查看\"}";
                    }
                    else
                    {
                        jdate = jdate + "{ \"id\":\"" + roleid + "-1\",  \"text\":\"管理\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-2\",  \"text\":\"编辑\"},";
                        jdate = jdate + "{ \"id\":\"" + roleid + "-3\",  \"text\":\"查看\",\"checked\":\"true\"}";
                    }
                    if (i == ds.Tables[0].Rows.Count - 1)
                    {
                        jdate = jdate + "]}";
                    }
                    else
                    {
                        jdate = jdate + "]},";
                    }
                }
                else
                {
                    jdate = jdate + "{ \"id\": \"" + roleid + "\",\"text\": \"" + rolename + "\",\"children\": [";
                    jdate = jdate + "{ \"id\":\"" + roleid + "-1\",  \"text\":\"管理\"},";
                    jdate = jdate + "{ \"id\":\"" + roleid + "-2\",  \"text\":\"编辑\"},";
                    jdate = jdate + "{ \"id\":\"" + roleid + "-3\",  \"text\":\"查看\"}";
                    if(i==ds.Tables[0].Rows.Count-1)
                    {
                        jdate = jdate + "]}";
                    }
                    else
                    {
                        jdate = jdate + "]},";
                    }
                }
            }
        }
        jdate = jdate + "]";
        return jdate;
    }
    //动态处理页面-角色点击事件
    [WebMethod]
    public string clsave(string rid, string pid, string qxdj,string bp)
    {
        string sql = "";
        DataSet ds;
        if (bp=="c")//单选事件
        {
            sql = "select *  from s_role where pid = '"+ pid + "' and roleid = '"+ rid + "'";
            ds = msql.Selbeck(sql);
            if(ds.Tables[0].Rows.Count>0)
            {
                sql = "update s_role set qxid = '" + qxdj + "' where pid = '" + pid + "' and roleid = '" + rid + "'";
            }
            else
            {
                string cid = msql.getmaxid("id", "s_role", "where roleid = '" + rid + "'");
                sql = "select * from s_role where roleid = '"+ rid + "'";
                DataSet dt = msql.Selbeck(sql);
                string rname = dt.Tables[0].Rows[0]["rolename"].ToString();
                sql = "insert into s_role (id,roleid,rolename,pid,qxid,jszt)Values('"+ cid + "','" + rid + "','" + rname + "','" + pid + "','" + qxdj + "',1)";
            }
            msql.Datachange(sql);
        }
        else if(bp == "q")//全选事件
        {
            sql = "select roleid,rolename,jszt from s_role where jszt = 1 group by  roleid,jszt,rolename order by roleid";
            ds = msql.Selbeck(sql);
            for(int i=0;i<ds.Tables[0].Rows.Count;i++)
            {
                string prid = ds.Tables[0].Rows[i]["roleid"].ToString();
                string rname = ds.Tables[0].Rows[i]["rolename"].ToString();
                sql = "select *  from s_role where pid = '" + pid + "' and roleid = '" + prid + "'";
                DataSet dc = msql.Selbeck(sql);
                if (dc.Tables[0].Rows.Count > 0)
                {
                    sql = "update s_role set qxid = '" + qxdj + "' where pid = '" + pid + "' and roleid = '" + prid + "'";
                }
                else
                {
                    string cid = msql.getmaxid("id", "s_role", "where roleid = '" + prid + "'");
                    sql = "insert into s_role (id,roleid,rolename,pid,qxid,jszt)Values('" + cid + "','" + prid + "','" + rname + "','" + pid + "','" + qxdj + "',1)";
                }
                msql.Datachange(sql);
            }
        }
        else if(bp == "u")//全不选事件
        {
            sql = "delete from s_role where pid = '" + pid + "'";
            msql.Datachange(sql);
        }
        return "0";
    }
    /**********************************************动态加载角色信息**************************************************/
    //调取菜单json
    [WebMethod]
    public string Getpg(string jsid,string bmid)
    {
        string jsinfo = qx.jscd(jsid, bmid);
        return jsinfo;
    }
    //全选或者全不选情况下批量设置页面部门权限
    [WebMethod]
    public string Setbm(string id, string pid, string uid, bool cz)
    {

        qx.bmpcg(id, pid, uid, cz);
        return "";
    }
    /**********************************************员工信息保存接口*********************************************************/
    [WebMethod]
    //员工列表信息获取接口
    public string Getygb(string[] cbxx)
    {
        string res = YG.Getygb(cbxx);
        return res;
    }
    [WebMethod]
    //员工详细信息获取接口
    public string[] Getyginfo(string workid)
    {
        string []res = YG.Getyginfo(workid);
        return res;
    }
    [WebMethod]
    //员工详细信息获取接口
    public string[] Getygjt(string workid)
    {
        string[] res = YG.Getygjtinfo(workid);
        return res;
    }
    [WebMethod]
    //员工详细信息获取接口
    public string[] Getygjy(string workid)
    {
        string[] res = YG.Getygjyinfo(workid);
        return res;
    }
    [WebMethod]
    //员工详细信息获取接口
    public string[] Getyggz(string workid)
    {
        string[] res = YG.Getyggzinfo(workid);
        return res;
    }
    [WebMethod]
    //员工详细信息获取接口
    public string[] Getygqt(string workid)
    {
        string[] res = YG.Getygqtinfo(workid);
        return res;
    }
    ///员工基本信息保存接口
    [WebMethod]
    public string YGJBXXSave(string [] cbxx)
    {
        string res = YG.YGJBXX(cbxx);
        return res;
    }
    [WebMethod]
    //员工家庭信息保存接口
    public string YGJTXXSave(string[] cbxx)
    {
        string res = YG.YGJTXX(cbxx);
        return res;
    }
    [WebMethod]
    //员工教育信息保存接口
    public string YGJYXXSave(string[] cbxx)
    {
        string res = YG.YGJYXX(cbxx);
        return res;
    }
    [WebMethod]
    //员工工作经历信息保存接口
    public string YGJLXXSave(string[] cbxx)
    {
        string res = YG.YGGZXX(cbxx);
        return res;
    }
    [WebMethod]
    //员工其他信息保存接口
    public string YGQTXXSave(string[] cbxx)
    {
        string res = YG.YGQTXX(cbxx);
        return res;
    }
    [WebMethod]
    //动态获取岗位下拉菜单
    public string[] Getgwlb(string bmid)
    {
        string[] res = YG.Getgwlb(bmid);
        return res;
    }
    //提取数值
    public string findnum(string info)
    {
        string result = "";
        string[] strArray = info.Split('(');
        if (strArray.Length > 1)
        {
            result = System.Text.RegularExpressions.Regex.Replace(strArray[0], @"[^0-9]+", "");
        }
        else
        {
            strArray = info.Split('（');
            result = System.Text.RegularExpressions.Regex.Replace(strArray[0], @"[^0-9]+", "");
        }

        return result;
    }
    /**********************************************获取公告信息*********************************************************/
    [WebMethod]
    public string[] GetGGinfo(string ggid,string uid)
    {
        string[] res = gg.GetGGinfo(ggid, uid);
        return res;
    }
    /**********************************************通讯录获取员工姓名*********************************************************/
    [WebMethod]
    public string Getworkname(string workid)
    {
        string res = tl.Getworkname(workid);
        return res;
    }
}

